﻿using Microsoft.AspNetCore.Http;
using MyWeb.ServiceBus.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace MyWeb.ServiceBus.Services.Impl
{
    public class OperatorProvider : IOperatorProvider
    {

        private readonly IHttpContextAccessor _httpContextAccessor;
        //services.AddHttpContextAccessor();
        public OperatorProvider(IHttpContextAccessor httpContextAccessor)
        {
            _httpContextAccessor = httpContextAccessor;
        }
        public SysUser GetUserInfo()
        {
            var json = _httpContextAccessor.HttpContext.Request.Headers["UserInfo"];
            if (!string.IsNullOrEmpty(json))
            {
                return JsonSerializer.Deserialize<SysUser>(json) ?? new SysUser();
            }
            return new SysUser();
        }
    }
}
